/**
 * @作者 7七月
 * @微信公号 林间有风
 * @开源项目 $ http://talelin.com
 * @免费专栏 $ http://course.talelin.com
 * @我的课程 $ http://imooc.com/t/4294850
 * @创建时间 2020-03-31 22:45
 */
package com.ruoyi.common.wxpay;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@Component
public class LinWxPayConfigSampleV2 extends WXPayConfig {

    @Value("${wx.private-key-path}")
    private String certFilePath;


    @Override
    public String getAppID() {
        return "wx5fe5ff3bc770000f";
    }

    @Override
    public String getMchID() {
        return "1699368179";
    }

    @Override
    public String getKey() {
        return "4d0c9064710e38be75dac5b00961c154";
    }

    @Override
    public InputStream getCertStream() {
        try {
            // 替换为你证书的文件路径
            String certFilePath = "/home/shopping/apiclient/apiclient_cert.p12";
           // String certFilePath = "E:\\cert\\apiclient_cert.p12";
            File certFile = new File(certFilePath);
            return new FileInputStream(certFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    @Override
    public IWXPayDomain getWXPayDomain() {
        IWXPayDomain iwxPayDomain = new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;
    }
}
